﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using SqlCon;

namespace yfxt
{
    public partial class gl_yprkd_you : Form
    {
        public gl_yprkd_you()
        {
            InitializeComponent();
        }

        private void gl_yprkd_you_Load(object sender, EventArgs e)
        {
            dataGridView1.AllowUserToResizeRows = false;                     //禁止用鼠标调整datagridView单元格的大小。
            dataGridView1.AllowUserToResizeColumns = false;
            foreach (DataGridViewColumn c in dataGridView1.Columns)        //禁止对datagridView列进行排序
            {
                c.SortMode = DataGridViewColumnSortMode.NotSortable;
            }

            string rukudanhao = ((gl_yprk)this.Owner).rukudanhao;
            DataTable dt = new DataTable();
            DataTable dt2 = new DataTable();

            //显示No.100001
            label6.Text = rukudanhao;

            //显示入库日期、备注
            string comStr = "select rkrq,rkbz,czgh,fhy from YF_RK01 where rkdh='" + rukudanhao + "'";
            dt2.Load(SqlHelper.ExecuteReader(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, comStr, null));
            textBox2.Text = Convert.ToDateTime(dt2.Rows[0][0]).ToString("yyyy-MM-dd").Replace('-', '.');
            textBox3.Text = dt2.Rows[0][1].ToString();

            //显示入库员
            comStr = "select ygxm from GY_YGDM where ygbh='" + dt2.Rows[0][2].ToString() + "'";
            string ygxm = (SqlHelper.ExecuteScalar(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, comStr, null)).ToString();
            textBox4.Text = ygxm;

            //显示复核员
            comStr = "select ygxm from GY_YGDM where ygbh='" + dt2.Rows[0][3].ToString() + "'";
            string ygxm2 = (SqlHelper.ExecuteScalar(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, comStr, null)).ToString();
            textBox5.Text = ygxm2;

            //显示datagridView1的
            comStr = "select yfsb,rkfs,rkdh,ypxh,ypgg,yfdw,ypcd,lsjg,rksl,lsje,ypph,ypxq from YF_RK02 where rkdh='" + rukudanhao + "'";
            dt.Load(SqlHelper.ExecuteReader(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, comStr, null));
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                dataGridView1.Rows.Add(1);

                //显示药品名称
                comStr = "select ypmc from yk_typk where ypxh='" + dt.Rows[i][3].ToString() + "'";
                string ypmc = (SqlHelper.ExecuteScalar(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, comStr, null)).ToString();
                dataGridView1.Rows[i].Cells[0].Value = ypmc;

                for (int j = 1; j < 9; j++)
                {
                    if (j != 3)
                    {
                        if (j == 8)
                        {
                            dataGridView1.Rows[i].Cells[j].Value = Convert.ToDateTime(dt.Rows[i][j + 3]).ToString("yyyy-MM-dd").Replace('-', '.');
                        }
                        else
                        {
                            dataGridView1.Rows[i].Cells[j].Value = dt.Rows[i][j + 3].ToString();
                        }
                    }
                    else
                    {
                        //显示产地
                        comStr = "select cdqc from YK_CDDZ where ypcd='" + dt.Rows[i][6].ToString() + "'";
                        string cdqc = (SqlHelper.ExecuteScalar(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, comStr, null)).ToString();
                        dataGridView1.Rows[i].Cells[3].Value = cdqc;
                    }
                }
            }

            //显示入库方式
            comStr = "select fsmc from YF_RKFS where yfsb='" + dt.Rows[0][0].ToString() + "'" +
                "and rkfs='" + dt.Rows[0][1].ToString() + "'";
            string fsmc = (SqlHelper.ExecuteScalar(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, comStr, null)).ToString();
            textBox1.Text = fsmc;

            //显示合计
            comStr = "select sum(lsje) from yf_rk02 where rkdh='" + dt.Rows[0][2].ToString() + "'";
            string total_lsje = (SqlHelper.ExecuteScalar(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, comStr, null)).ToString();
            textBox6.Text = total_lsje;
        }

        private void button4_Click(object sender, EventArgs e)
        {
            this.Close();
        }

    }
}
